package com.library.tag;


import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

public class WelcomeTag extends SimpleTagSupport {

    // 属性：额外样式类
    private String welcomeCss;

    public void setWelcomeCss(String welcomeCss) {
        this.welcomeCss = this.welcomeCss;
    }

    @Override
    public void doTag() throws JspException, IOException {
        PageContext pc = (PageContext) getJspContext();
        HttpSession session = pc.getSession();
        String welcome = (String) session.getAttribute("welcome");

        JspWriter out = pc.getOut();
        out.print("<br><span class=\"welcome-tag");
        if (welcomeCss != null && !welcomeCss.isEmpty()) {
            out.print(" " + welcomeCss);
        }
        out.print("\">");
        out.print(welcome);
        out.print("</span><br>");
    }
}
